package com.chb.properties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;

/**
 * @description:
 * @author: CHB
 * @create: 2021-10-28 15:29
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "sparrow.security")
public class SecurityConfigProperties implements InitializingBean {

    /**
     * jwt 密钥
     */
    private String jwtSecret;

    /**
     * jwt 有效期（单位 秒）
     */
    private Long jwtExpiration;

    /**
     * 请求头token名称
     */
    private String tokenHeaderName = "Authorization";

    /**
     * token 内容前缀
     */
    private String tokenPrefix = "Bearer ";

    /**
     * security 不拦截地址
     */
    private String[] anonymousPath;

    @Override
    public void afterPropertiesSet() throws Exception {
       Assert.hasText(this.jwtSecret, "jwt-secret must be set");
       Assert.notNull(this.jwtExpiration, "jwt-expiration-ms must be set");
       Assert.notNull(this.tokenHeaderName, "jwt-token-name must be set");
       Assert.notNull(this.tokenPrefix, "jwt-token-prefix must be set");
    }
}
